import {NativeModules} from 'react-native';

const {RNSharePreference} = NativeModules;
//此模块是key-value存储模块
const SharePreference = {
  /**
   * 使用key 存储 value
   * @param saveKey string
   * @param saveValue string
   * @return {Promise<*|boolean|boolean>}
   */
  async saveValue(saveKey, saveValue) {
    try {
      let result = await RNSharePreference.saveValue(saveKey, saveValue);
      return result;
    } catch (e) {
      return false;
    }
  },
  /**
   * 获取key获取value值
   * @param key string
   * @return {Promise<null|*>}
   */
  async getValue(key) {
    try {
      let result = await RNSharePreference.getValue(key);
      return result;
    } catch (e) {
      return null;
    }
  },
  /**
   * 移除key对应的value值
   * @param key string
   * @return {Promise<*|boolean|void|boolean>}
   */
  async remove(key) {
    try {
      let result = await RNSharePreference.remove(key);
      return result;
    } catch (e) {
      return false;
    }
  }

}

export default SharePreference;
